import Sequelize from 'sequelize'
import db from '../database'

const ProfessionInfo = db.define('profession_info',{
	id:{
		type: Sequelize.INTEGER,
        autoIncrement:true,
        allowNull: false
	},
    pno:{
    	type:Sequelize.STRING,
    	primaryKey:true,
    	allowNull: false
    },
    pname:{
    	type:Sequelize.STRING,
    }
},{
	freezeTableName:false,
	tableName:'profession_info',
	updatedAt:'update_time',
    createdAt:'create_time'
});

class ProfessionModel {
	add(record){
		return ProfessionInfo.create(record);
	}

	update(record){
		return ProfessionInfo.update(record,{
			where:{
				pno:record.pno
			}
		})
	}

	delete(id){
		return ProfessionInfo.destroy({
			where:{
				pno:id
			}
		})
	}

	findById(id){
		return ProfessionInfo.findById(id);
	}

	findByPage(record){
		return ProfessionInfo.findAndCount({
			limit: record.page_size,
			offset: record.page_size * (record.page_no - 1)
		})
	}

	findAllData(param){
		return ProfessionInfo.findAll({
			where: param
		})
	}
}

module.exports = new ProfessionModel();